package com.qidian.mes.pro.controller;

import com.qidian.mes.pojo.pro.ProProcess;
import com.qidian.mes.pro.service.ProProcessService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/10/30 18:51
 * @Description
 **/
@RestController
@RequestMapping("/process")
@CrossOrigin
public class ProProcessController {
    @Autowired
    ProProcessService proProcessService;
    @GetMapping("/get")
    public MESResult get(int page,int limit){
        return proProcessService.selectallByPage(page,limit);
    }
    @GetMapping("/list")
    public MESResult list(int page, int limit, ProProcess proProcess){
        return proProcessService.list(page,limit,proProcess);
    }
    @GetMapping("/genProcessCode")
    public MESResult genProcessCode(){
        return proProcessService.genProcessCode();
    }
    @PostMapping("/save")
    public MESResult proProcess(@RequestBody ProProcess proProcess){
        System.err.println(proProcess);
        if (proProcess.getEnableFlag()=='1') {
            proProcess.setEnableFlag('Y');
        }
        else {
            proProcess.setEnableFlag('N');
        }
        return proProcessService.save(proProcess);
    }
    @DeleteMapping("/deleteProcess")
    public MESResult deleteProcess(String processCode){
        return proProcessService.deleteProcess(processCode);
    }
   @PostMapping("/update")
    public MESResult updateProcess(@RequestBody ProProcess process){

       if (process.getEnableFlag()=='1'){
           process.setEnableFlag('Y');
       }
       else if (process.getEnableFlag()=='2')
       {
           process.setEnableFlag('N');
       }

       return proProcessService.updateProcess(process);
   }
@GetMapping("/selectall")
    public MESResult selectall(){
        return proProcessService.selectall();
}
}
